<?php
load_info_var($cf_controller);	   //加载smarty变量
load_file('suggestion_class', LIB_PATH);

$main = new Suggestion($db);
$id = isset($_POST['id']) ? intval($_POST['id']) : intval($_GET['id']);
$self = isset($_POST['self']) ? $_POST['self'] : $_GET['self'];
$return_page = $cf_pre_page ? $cf_pre_page : $cf_self_page;

switch ($cf_action) {
    case "index":
	$smarty->mypage($cf_controller, $cf_action, 0);
	$skey = isset($_POST['skey']) ? trim($_POST['skey']) : urldecode($_GET['skey']);
	$skey2 = isset($_POST['skey2']) ? trim($_POST['skey2']) : urldecode($_GET['skey2']);
	$skey3 = isset($_POST['skey3']) ? trim($_POST['skey3']) : urldecode($_GET['skey3']);

	$where = '1';
	if ($skey) {
	    $where .= " and sug_name like '%" . $skey . "%'";
	}
	if ($skey2 && $skey3) {
	    $where .= " and DATE_FORMAT(sug_create_time,'%Y-%m-%d') between '$skey2' and '$skey3' ";
	}
	

	load_file('page_class', LIB_PATH);
	$MyPage = new Mypage($db);
	$field = '*';
	$data_ary = $MyPage->from_sql($field, $main->get_table_name(), $where, "sug_id DESC", intval($_GET['cpage']), "20");
	$page = $MyPage->get_page($data, $cf_self_page . '?dpt=' . $cf_dpt . '&skey=' . $skey . '&skey2=' . $skey2 . '&skey3=' . $skey3 . '&stype=' . $stype . '&stype2=' . $stype2. '&self=' . $self);
	
	

	break;
    case "edit":	

		$data = $db->getFormData($main->get_table_name(),$_POST);	 
		$data['sg_reply_admin'] = $cf_admin_info['admin_name'];
		$data['sg_status'] = '1';		
		$data['sg_reply_time'] = date("Y-m-d H:i:s");	    
	    $result = $main->update_data($data, "sg_id = '$id'");

	    if ($result) {
			my_page('操作成功!',1);
	    } else {
			my_page('操作失败!',0);
	    }
	break;
    case "del":
	$result = $main->del_data("sg_id='$id'");

	if ($result) {
	    my_jump('删除成功', '', $return_page, 1);
	} else {
	    my_jump('删除失败!');
	}

	break;
    case "all":
	$alltype = $_POST['alltype'];
	$idlist = $_POST['idlist'];
	if ($idlist) {
	    $list = implode(",", $idlist);
	    switch ($alltype) {
		case "alldel":
		    $result = $main->del_data("sg_id in (" . $list . ")");
		    break;
		case "allcheck":
		    $data = array('sg_check' => '1', 'sg_check_info' => $cf_admin_info['admin_name'] . ' ' . date("y-m-d H:i:s"));
		    $result = $main->update_data($data, "sg_id in (" . $list . ")");
		    break;

		default:
		    my_jump('请指定操作方式');
		    break;
	    }
	    if ($result)
		my_jump('操作成功', '', $return_page, 1);
	    else
		my_jump('操作失败');
	}else {
	    my_jump('输入的参数有误');
	}
	break;
    default:
	my_jump('非法操作!');
	break;
}

$smarty->assign(array(
    'id' => $id,
    'row' => htmlchar($row),
    'data_ary' => $data_ary,
	'total_cost' => $total_cost,
	'total_get' => $total_get,
    'page' => $page,
    'self' => $self,
    'skey' => $skey,
    'skey2' => $skey2,
    'skey3' => $skey3,
    'stype' => $stype,
    'stype2' => $stype2,
    'datas1' => $datas1,
    'group' => $group,
    'result' => $result,
    'sum' => $sum,
    'type' => add_array_item(array('' => '全部'), $cf_info_var_common['sg_type'])
));


$smarty->mydisplay();
?>